package fun.hijklmn.magic.common.vo.resp;

import fun.hijklmn.magic.common.vo.req.PageVO;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @Description
 * @Author fs
 * @Date 2021/4/29 16:09
 * @Version 0.0.1-SNAPSHOT
 **/
@Data
public class PageResultVO<T> implements Serializable {

    private Integer currentPage;

    private Integer pageSize;

    private Integer totalNum;

    private Integer totalPage;

    private List<T> items;

    public PageResultVO(Integer currentPage, Integer pageSize, Integer totalNum, List<T> items) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalNum = totalNum;
        this.totalPage = pageSize == 0 || pageSize == null ? 0 : (totalNum % pageSize == 0) ? totalNum / pageSize : totalNum / pageSize + 1;
        this.items = items;
    }

    public PageResultVO(PageVO pageVO, Integer totalNum, List<T> items) {
        this.currentPage = pageVO.getCurrentPage();
        this.pageSize = pageVO.getPageSize();
        this.totalNum = totalNum;
        this.totalPage = pageSize == 0 || pageSize == null ? 0 : (totalNum % pageSize == 0) ? totalNum / pageSize : totalNum / pageSize + 1;
        this.items = items;
    }

}
